** Data reading and variable selection from raw data
** International Social Survey Panel (ISSP), GBR 1986


** 01. Reading data **

cap log close
clear all
set more off
cd /*insert you work directory here*/
use /*read your data here*/  
numlabel, add


** 02. Constructing year and country variables **

ge year=1986
lab var year "survey year"

ge country=826
lab var country "ISO country code"
//United Kingdom: 826 (ISO Country Codes) 


** 03. ID variables **

ge pid=v2
lab var pid "person id"

ge cid=v3
lab var cid "country id"
keep if cid==3


** 04. Basic Demographics (Sex and Age/birth year) **

ge sex=v81
lab var sex "sex"
lab def sex 1 "male" 2 "female"
lab val sex sex

ge age=v80
lab var age "age"

ge birthyr=year-age
lab var birthyr "year of birth"


** 05. Siblings **

ge nbro=v16 

ge nsis=v12
* q19_1 and q19_2 include respondent

ge nsibs=nbro+nsis

lab var nbro "number of brothers aged 18 or older"
lab def nbro 05 "Five or more"
lab val nbro nbro
lab var nsis "number of sisters aged 18 or older"
lab def nsis 05 "Five or more"
lab val nsis nsis


** 06. Own education **

ge schooling=v85
lab var schooling " Yeas in school--completed continuous full-time education"

ge educ=v86
lab var educ "highest level of education completed"
lab def educ 3 "No secondary qualifications" 4 "CSE" 5 "O Level" 6 "A Level" 7 "Higher education below degree level" 8 "Degree" 9 "Foreign and other" 0 "NA, don't know"
lab val educ educ


** 07. Parents' education: Father and/or Mother **

//no information about parents' education in this dataset


** 08. Own occupation **

ge occ=v73
ge empstat=v72
lab var occ "Present and last occupation"
lab var empstat "employment status"

lab def empstat 1 "unemployed" 2 "employed"
lab val empstat empstat


** 09. Parents' occupation **

ge faocc=v102
lab var faocc "father's occupation"


** 10. Tabulate the Identified Variables **

log using /*insert you work directory here*/, replace text

** Data reading and variable selection from raw data
** International Social Survey Panel, GBR 1986

** Sex **
tab sex

** Age, Birth Year **
sum age birthyr, d

** Siblings **
sum nsibs nbro nsis , d

** R's Own Education **
tab1 schooling educ 

** R's Own Occupation **
tab1 occ empstat 

** Parental Occupation **
tab1 faocc 

log close

** 11. Keep the identified variables only

keep year country pid cid sex age birthyr ///
	 nbro nsis nsibs ///
	 schooling educ ///
	 occ empstat faocc


** 12. Save the Data File **

saveold /*insert you work directory here*/, replace


** 13. Homoginising education **
** Own Education **
rename educ educ_cat
rename schooling educ_yrs
//code missing variables
replace educ_yrs=. if educ_yrs==-2 

ge educ_ISCED=100 if educ_cat==3
replace educ_ISCED=244 if educ_cat==4
replace educ_ISCED=244 if educ_cat==5
replace educ_ISCED=344 if educ_cat==6
replace educ_ISCED=354 if educ_cat==7
replace educ_ISCED=665 if educ_cat==8
replace educ_ISCED=. if educ_cat==9
lab var educ_ISCED "respondent highest education in ISCED code"

** Parents Education **

//parents education not available


** 14. Homoginising sibling **
//cutoff
ge nsibs_flag=10
ge nbro_flag=5
ge nsis_flag=5
lab var nsibs_flag "cutoff of total number of siblings"
lab var nbro_flag "cutoff of total number of brothers"
lab var nsis_flag "cutoff of total number of sisters"


** 15. Tab Education and Sibling Variables **
tab1 sex age birthyr
tab1 educ_cat educ_yrs 
tab1 nsibs nbro nsis nsibs_flag nbro_flag nsis_flag


** 16. Save the Data File **

saveold /*insert you work directory here*/, replace
